Skip to content

feat(layout): support listener, loader, and component modifiers - #307

Merged
wpoortman merged 13 commits into
mainfrom
feat/layout-listener-overrides
Sep 23, 2026
Merged

wpoortman merged 13 commits into
mainfrom
feat/layout-listener-overrides

Conversation

@wpoortman

@wpoortman wpoortman commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve the original Portman-owned SupportEvents registration unchanged.
  • Register an independent SupportMagewireEvents adapter immediately after core events.
  • Share layout argument lookup and overlays through LayoutArgumentOverlay, so features can opt into per-placement values without duplicating merge logic.
  • Support listener additions, handler replacements, and keyed false / null removals through magewire:listeners.
  • Support loader additions, replacements, and keyed null removals through magewire:loader; false remains a valid loader value.
  • Accept an array of PHP ModifierInterface objects through magewire:modifiers. The interface extends Magento's block ArgumentInterface for layout object resolution. Each modifier receives a ComponentModifierContext with the component and the generic MagewireArguments collection; the context can expose other build data later without changing the interface.
  • Preserve Magento Phrase values in loader effects. PHP modifier messages remain visible to i18n:collect-phrases.
  • Keep Magento layout and resolver knowledge outside Portman-owned files.

Architecture

LayoutArgumentOverlay reads resolver arguments, replaces scalar values, appends list entries, and merges named entries with consumer-selected removal values. Event-specific listener normalization and dispatch guards remain in SupportMagewireEvents. The loader feature uses the same overlay before translating and dehydrating its effect, without mutating the component property.

ComponentModifierRunner applies declared modifiers in array order after block arguments are assembled and before component assembly, mount, or hydration. Modifiers can use MagewireArguments::get() and merge() to change any argument or change the component directly. Conditions can inspect Magento services and the component's initialized state at that point; snapshot state has not yet been hydrated.

<argument name="magewire:modifiers" xsi:type="array">
    <item name="configure" xsi:type="object" shared="false">Vendor\Module\Modifier\Configure</item>
</argument>

Active layout handlers are contributed during the event adapter boot hook, before server calls and dehydration. Tombstoned dispatches are rejected by a pre-call guard, and the adapter later filters the initial browser listener effect during dehydration. If core events are disabled, the adapter skips itself.

Listener precedence remains component listeners, then On attributes, then the layout overlay. Tombstones are resolved before dynamic placeholders are expanded. Whole-map clearing and live post-mount reconciliation remain out of scope.

Verification

  • PHPUnit unit suite: 40 tests, 98 assertions locally.
  • Mago lint and formatting checks, PHP syntax, XML parsing, JavaScript syntax, and git diff --check pass locally.
  • Magento i18n:collect-phrases finds both PHP modifier messages.
  • The /magewire/playwright/events route and Playwright spec exercise XML listeners, the loader overlay, and the modifier object (including PHP-computed listeners and Phrase messages); GitHub CI runs them against Magento.

@wpoortman wpoortman added the V3 label Sep 16, 2026
@wpoortman
wpoortman added this pull request to stack #309 September 22, 2026 17:07
@wpoortman wpoortman changed the title feat(events): add layout listener overrides feat(layout): support listener and loader argument overlays Sep 23, 2026
@wpoortman wpoortman changed the title feat(layout): support listener and loader argument overlays feat(layout): support listener, loader, and PHP argument modifiers Sep 23, 2026
@wpoortman wpoortman changed the title feat(layout): support listener, loader, and PHP argument modifiers feat(layout): support listener, loader, and component modifiers Sep 23, 2026
) {
}

public function getComponent(): Component

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we return a object, dont use get, just make the method component()

return $this->component;
}

public function getArguments(): MagewireArguments

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it returns an object, we don't need a get, we can just use arguments() as a method.

@wpoortman
wpoortman marked this pull request as ready for review September 23, 2026 19:05
@wpoortman
wpoortman merged commit c88e68e into main Sep 23, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant